<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\services\DatabaseService;
use think\App;

class Databases extends Common
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->service = DatabaseService::getInstance();
    }

    // 数据表列表
    public function index()
    {
        $list = $this->service->getAllTabels(true);
        return view($this->view_page, compact('list'));
    }

    // 修复表
    public function repair($table)
    {
        if ($this->service->setRepair($table)){
            return $this->successJson([], $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }

    // 优化表
    public function optimization($table)
    {
        if ($this->service->setOptimization($table)){
            return $this->successJson([], $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }

    // 批量修复表
    public function repairAll()
    {
        $this->service->setRepairAll();
        return $this->successJson([], $this->service->getError());
    }

    // 批量优化表
    public function optimizationAll()
    {
        $this->service->setOptimizationAll();
        return $this->successJson([], $this->service->getError());
    }

    // 备份记录
    public function backups()
    {

    }

    // 备份数据库
    public function backup()
    {

    }

    // 恢复到指定SQL文件
    public function restore()
    {

    }
}
